<?php
session_start();
if (isset($_SESSION["username"])) {
?>
    <?php require_once('common/header.php'); ?>
    <!--页面主要内容-->
    <main class="lyear-layout-content">
        <div class="container-fluid">
            <div class="card">
                <div class="card-header bg-primary">
                    <h4>添加产品</h4>
                </div>
                <div class="card-body">
                    <form class="form-horizontal" action="controller/tianjia.php" method="POST">
                        <div class="form-group">
                            <label class="col-xs-12">名称：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="name" placeholder="请输入产品名称" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12">提单接口：</label>
                            <div class="col-xs-12">
                             <select class="form-control" id="provider" onchange="toggleInput()" name = "api_type">
                              <option value="yqrapi" selected>172系统</option>
                              <option value="yidong">移动</option>
                              <option value="hnhklt">海南联通</option>
                              <option value="zgdx">电信</option>
                              <option value="gantanhao">感探号</option>
                              <option value="haokeyun">号氪云</option>
                            </select>
                            </div>
                        </div>
                        <div class="form-group" id="haokaidGroup" style="display: none;" >
                            <label class="col-xs-12">172号卡商品id：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="yqrid" placeholder="没有可填0" >
                            </div>
                        </div>
                     
                        <div class="form-group" id="ltGroup" style="display: none;" >
                            <label class="col-xs-12">联通产品类型：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="productType" placeholder="联通产品类型ID" >
                            </div>
                        </div>
                        <div class="form-group" id="xhGroup" style="display: none;" >
                            <label class="col-xs-12">是否支持选号：</label>
                            <div class="col-xs-12">
                                <select class="form-control" name ="se_num">
                                  <option value="0" selected>不支持</option>
                                  <option value="1">支持</option>
                                </select>
                            </div>
                        </div>
                        
                           <div class="form-group" id="haoke" style="display: none;" >
                            <label class="col-xs-12">号氪产品编号：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="goodsCode" placeholder="号氪产品编号" >
                            </div>
                        </div>
                         <div class="form-group" id="gantan" style="display: none;" >
                            <label class="col-xs-12">感叹号产品编号：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="sku" placeholder="感叹号产品编号" >
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label class="col-xs-12">下单模版：</label>
                            <div class="col-xs-12">
                             <select class="form-control"  name = "downtel">
                              <option value="one" selected>默认模板-系统平台模版</option>
                              <option value="two">蓝色互动模版-不支持选号</option>
                            </select>
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label class="col-xs-12">介绍：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="jieshao" placeholder="请输入产品简短介绍" >

                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12">时长：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="ltime" placeholder="套餐时长,建议四个字" >
                            </div>
                        </div>
                        <div class="form-group">
                            <?php
                            include_once("../untils/conn.php");
                            mysqli_query($con, "set names utf8");
                            if ($con) {
                                //选择数据库
                                if ($db) {
                                    //获取数据总行数
                                    $sortsql = "select * from sort";
                                    $sortdata = mysqli_query($con, $sortsql);
                            ?>
                                    <label class="col-xs-12">运营商：</label>
                                    <div class="col-xs-12">
                                        <select name="yys" id="yys" class="form-control">
                                            <?php
                                            while ($sortrow = mysqli_fetch_array($sortdata)) {
                                            ?>
                                                <option value="<?php echo $sortrow["yys"] ?>" name="<?php echo $sortrow["yys"] ?>"><?php echo $sortrow["yys"] ?></option>
                                            <?php
                                            }

                                            ?>
                                        </select>

                                    </div>

                            <?php
                                }
                            }

                            ?>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12">限龄：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="other" placeholder="可以写限龄，或其他，用于显示前台，可为空" >
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12">归属地：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="gsd" placeholder="请输入号卡归属地" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12">商品标签：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="xuanhao" placeholder="商品标签" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12">包邮方式：</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="baoyou" placeholder="可输入全国免费包邮/京东物流等" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12">主图链接：</label>
                            <div class="col-xs-12">
                                <input type="url" class="form-control" name="zhutu" placeholder="主图URL地址" required>

                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12">详情图</label>
                            <div class="col-xs-12">
                                <input type="url" class="form-control" name="link" placeholder="请输入详情图地址" required>

                            </div>
                        </div>
                         <div class="form-group">
                            <label class="col-xs-12">商品真实佣金（填写真实佣金用于数据计算）</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="price" placeholder="商品佣金" required>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-xs-12">代理佣金（用于结算代理的佣金，请用商品说明一致）</label>
                            <div class="col-xs-12">
                                <input type="text" class="form-control" name="proxy_price" placeholder="商品佣金" required>
                            </div>
                        </div>
                         <div class="form-group">
                            <label class="col-xs-12" for="notes">商品说明（代理看到的佣金说明）</label>
                            <div class="col-xs-12">
                              <textarea class="form-control"  name="notes"  placeholder="商品代理说明"></textarea>
                            </div>
                          </div>
                        <div class="form-group">
                            <div class="offset-2 col-xs-12">
                                <button class="btn btn-success" type="submit" value="添加">添加</button>
                                <button class="btn btn-danger ml-3" type="reset" value="重置">重置</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </main>
   <script>
    window.onload = function() {
        toggleInput();
    };

    function toggleInput() {
        var provider = document.getElementById("provider").value;
        var haokaidGroup = document.getElementById("haokaidGroup");
        var ltGroup = document.getElementById("ltGroup");
        var xhGroup = document.getElementById("xhGroup");
        var haoke = document.getElementById("haoke");
        var gantan = document.getElementById("gantan");

        if (provider === "yqrapi") {
            haokaidGroup.style.display = "block";
            ltGroup.style.display = "none";
            xhGroup.style.display = "none";
            haoke.style.display = "none";
            gantan.style.display = "none";
        } else if (provider === "hnhklt") {
            haokaidGroup.style.display = "none";
            ltGroup.style.display = "block";
            xhGroup.style.display = "block";
            haoke.style.display = "none";
            gantan.style.display = "none";
        } else if (provider === "haokeyun") {
            haokaidGroup.style.display = "none";
            ltGroup.style.display = "none";
            xhGroup.style.display = "none";
            haoke.style.display = "block";
            gantan.style.display = "none";
        } else if (provider === "gantanhao") {
            haokaidGroup.style.display = "none";
            ltGroup.style.display = "none";
            xhGroup.style.display = "none";
            haoke.style.display = "none";
            gantan.style.display = "block";
        } else {
            haokaidGroup.style.display = "none";
            ltGroup.style.display = "none";
            xhGroup.style.display = "none";
            haoke.style.display = "none";
            gantan.style.display = "none";
        }
    }
</script>

    <!--End 页面主要内容-->
    <?php require_once('common/footer.php'); ?>
<?php
} else {
    echo "<script>alert('您尚未登录，没有权限访问该页面');location.href='login.php';</script>";
}
?>